<template>
  <a-form
    :model="formState"
    ref="formDataRef"
    name="basic"
    :label-col="{ style: 'width:110px' }"
    :wrapper-col="{ style: 'calc(100% - 110px)' }"
    autocomplete="off"
    @finish="onFinish"
    @finishFailed="onFinishFailed"
  >
    <a-form-item label="期望取件时间" name="expectedPickupTime" :rules="[{ required: true, message: '请选择期望取件时间!' }]">
      <a-date-picker v-model:value="formState.expectedPickupTime" show-time placeholder="请选择" />
    </a-form-item>
    <a-form-item :wrapper-col="{ offset: 8, span: 16 }" class="submit-btn-form-item">
      <a-button :loading="loading" type="primary" html-type="submit">确定</a-button>
      <a-button @click="resetHandle">取消</a-button>
    </a-form-item>
  </a-form>
</template>

<script lang="ts" setup>
import { toRefs, watch } from "vue";
import InitHook from "./composables/initHook";
import OperationHook from "./composables/operationHook";
import dayjs from "dayjs";
const props = withDefaults(
  defineProps<{
    visible: boolean;
    passData: ClientAdvanceManagement.ListRows;
    type: number;
  }>(),
  {}
);
const emit = defineEmits<{
  (e: "update:visible", blo: boolean): void;
  (e: "submit"): void;
}>();
const { visible, passData, type } = toRefs(props);
const { formDataRef, formState, loading } = InitHook();
const { onFinish, onFinishFailed, resetFields, resetHandle } = OperationHook({
  formDataRef,
  formState,
  passData,
  emit,
  type,
  loading
});
const init = () => {
  if (type.value === 2 && passData.value.expectedPickupTime) {
    formState.expectedPickupTime = dayjs(Number(passData.value.expectedPickupTime));
  }
};
watch(
  () => visible.value,
  (v: boolean) => {
    if (v) {
      init();
    } else {
      resetFields();
      formDataRef.value.clearValidate();
    }
  }
);
init();
</script>
<style lang="stylus" scoped>
:deep(.ant-picker){
    width: 100%;
}
</style>
